<!DOCTYPE html>
<html>
<head>
    <include file="public/public_css" />
</head>
<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper">

    <include file="public/header-min" />
    <!-- Left side column. contains the logo and sidebar -->
    <include file="public/left" />
    <!-- Content Wrapper. Contains page content -->
    <div class="content-wrapper">
        <!-- Content Header (Page header) -->
        <section class="content-header">
            <h1>
                分类管理
                <a href="javascript:void(0);" onclick="addTag();"><button type="button" class="btn btn-primary">添加标签</button></a>
            </h1>
            <ol class="breadcrumb">
                <li><a href="#"><i class="fa fa-dashboard"></i>首页</a></li>
                <li class="active">标签管理</li>
            </ol>
        </section>

        <!-- Main content -->
        <section class="content">
            <!-- Small boxes (Stat box) -->
            <!-- Small boxes (Stat box) -->
            <div class="row">
                <table id="menuList" class="table table-hover">
                    <tr>
                        <th>标签id</th>
                        <th>标签名称</th>
                        <th>添加日期</th>
                        <th>操作</th>
                    </tr>
                    <volist name="list" id="vo">

                        <td>{$vo.tag_id}</td>
                        <td>{$vo.tag_name}</td>
                        <td>{:date('Y-m-d H:i:s', $vo.add_time)}</td>
                        <td>
                            <a class="delCat" href="javascript:void(0);" >
                                <input type="hidden" value="{$vo.tag_id}">
                                <button type="button" class="btn btn-danger">删除</button>
                            </a> |
                            <a class="editCat" href="javascript:void(0);">
                                <input type="hidden" value="{$vo.tag_id}">
                                <button type="button" class="btn btn-info">修改</button>
                            </a>
                        </td>
                        </tr>
                    </volist>
                </table>
            </div>
        </section>
        <!-- /.content -->
    </div>
    <!-- /.content-wrapper -->
    <include file="public/footer" />

    <!-- Control Sidebar -->

    <!-- /.control-sidebar -->
    <!-- Add the sidebar's background. This div must be placed
         immediately after the control sidebar -->
    <div class="control-sidebar-bg"></div>
</div>
<!-- ./wrapper -->

<include file="public/public_js" />

<script>
    //添加标签
    function addTag(){
        layer.open({
            type: 2,
            area: ['750px', '550px'],
            fixed: false, //不固定
            maxmin: true,
            content: '{$Think.WEB_PATH}/Admin/Content/addTag'
        });
    }
    //修改标签
    $('.editCat').click(function(){
        var tag_id = $(this).children("input").val();
        layer.open({
            type: 2,
            area: ['900px', '650px'],
            fixed: false, //不固定
            maxmin: true,
            content:  '{$Think.WEB_PATH}/Admin/Content/editTag?tag_id='+tag_id
        });
    });
    //删除标签
    $('.delCat').click(function(){
        var tag_id = $(this).children("input").val();
        layer.open({
            btn: ['删除', '取消'],
            yes: function(){
                $.ajax({
                    type : 'POST', //GET,POST
                    url: '{$Think.WEB_PATH}/Admin/Content/delTag?tag_id='+ tag_id,
                    dataType : 'json', //xml,json,script，默认为null
                    success : function (data) {
                        layer.open({
                            type: 1,
                            time: 1000,
                            area: ['200px', '200px'],
                            content: data.msg //服务器返回的消息
                        });
                        setTimeout(function(){
                            window.location.reload();
                        },1200);
                    },
                    error : function (event, errorText, errorType) { //错误时调用
                        alert(errorText + errorType);
                    }
                })
            },
            no: function(){

            },
            fixed: false, //不固定
            maxmin: true,
            content:'确定要删除吗？'
        });
    });


    //排序
    var  list_order = [];
    $("input[name='list_order']").change(function(){
        list_order[$(this).data('cat_id')] = $(this).val(); //以菜单ID作为数据key, 排序值作为val为数组
    });
    $('#listOrder').click(function(){
        list_order = $.toJSON(list_order); //格式化JS数组，将其转化为JSON格式发送到服务
        $.ajax({
            type: 'POST', //GET,POST
            url: '{$Think.WEB_PATH}/Admin/content/orderCat',
            data:{list_order:list_order},
            dataType: 'json', //xml,json,script，默认为null
            success: function (data) {
                layer.open({
                    type: 1,
                    time: 5000,
                    area: ['200px', '200px'],
                    content: data.msg //服务器返回的消息
                });
                setTimeout(function () {
                    window.location.reload();
                }, 1200);
            },
            error: function (event, errorText, errorType) { //错误时调用
                alert(errorText + errorType);
            }
        })
    });
</script>
</body>
</html>
